package com.lagou.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.lagou.model.Response;
import com.lagou.model.dto.AddOrderResp;
import com.lagou.model.dto.PayOrderResp;
import com.lagou.service.OrderService;
import java.io.UnsupportedEncodingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

  @Autowired
  private OrderService orderService;

  /**
   * 下单
   *
   * @param customerId
   * @return
   */
    @RequestMapping(value = "/add/{customerId}", method = RequestMethod.GET)
    public Response<AddOrderResp> addOrder(@PathVariable("customerId") Integer customerId)
        throws UnsupportedEncodingException, JsonProcessingException {
    return orderService.addOrder(customerId);
  }

  /**
   * 支付订单
   *
   * @param orderId
   * @return
   */
  @RequestMapping(value = "/pay/{orderId}", method = RequestMethod.GET)
  public Response<PayOrderResp> payOrder(@PathVariable("orderId") Integer orderId) {
    return orderService.payOrder(orderId);
  }

}
